// Last Update:2014-08-08 00:26:46
/**
 * @file server.cpp
 * @brief 
 * @author zealoussnow@163.com
 * @version 0.1.00
 * @date 2014-08-07
 */

#include <iostream>
#include <string.h>
#include "udp_server.h"

using namespace std;

int main(int argc, char *argv[])
{
    UdpServer server;
    server.Init(9000);

    char buf[8192];
    in6_addr clientIp;
    uint16_t clientPort;

    while (1)
    {
        memset(buf, 0, sizeof(buf));
        uint32_t ret = server.Recv(buf, 8192, &clientIp, &clientPort);
        if (ret > 0)
        {
            cout << "Received buf: " << buf << endl;
            char ipv6[48];
            memset(ipv6, 0, sizeof(ipv6));
            inet_ntop(AF_INET6, &clientIp, ipv6, sizeof(buf));
            cout << "Client info: " << ipv6 << ":" << ntohs(clientPort) << endl;
            //memset(ipv6, 0, sizeof(ipv6));
            //inet_pton(AF_INET6, );
        }
    }

    return 0;
}
